package com.ftg.learn.rabbitmq.simply;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 *
 * @author 布衣
 */
public class Provider {

    public static void main(String[] args) {
        String queueName = "q01";
        ConnectionFactory factory = new ConnectionFactory();
//        factory.setHost("localhost");
//        factory.setPort(5672);
//        factory.setUsername("guest");
//        factory.setPassword("guest");
//        factory.setVirtualHost("/");
        try (
                Connection connection = factory.newConnection();
                Channel channel = connection.createChannel()
        ) {

            channel.queueDeclare(queueName, false, false, false, null);
            String message = "Hello World ni hao";
            channel.basicPublish("", queueName, null, message.getBytes());
            System.out.println(" [x] Sent '" + message + "'");

        } catch (IOException | TimeoutException e) {
            throw new RuntimeException(e);
        }
    }

    //  生成数据  发送到rabbitmq

    //1 创建连接

    //2 创建channel

    //2.1 创建队列

    //3 发送消息

    //4 关闭资源

}
